﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EnumerableExtensions
{

    static class Extensions
    {

        public static decimal SumElements<T>(this IEnumerable<T> collection)
        {
            decimal result = 0;
            foreach (var value in collection)
            {
                result += Convert.ToDecimal(value);
            }
            return result;
        }

        public static decimal ProductElements<T>(this IEnumerable<T> collection)
        {
            decimal result = 1;
            foreach (var value in collection)
            {
                result *= Convert.ToDecimal(value);
            }
            return result;
        }

        public static decimal Average<T>(this IEnumerable<T> collection)
        {
            decimal result = 0;
            decimal count = 0;
            foreach (var value in collection)
            {
                result += Convert.ToDecimal(value);
                count++;
            }
            return result / count;
        }

        public static T GetMinElement<T>(this IEnumerable<T> collection)
            where T : IComparable<T>
        {
            T result = collection.First();
            foreach (var value in collection)
            {
                if (result.CompareTo(value) > 0)
                    result = value;
            }
            return result;
        }

        public static T GetMaxElement<T>(this IEnumerable<T> collection)
            where T: IComparable<T>
        {

            T result = collection.First();
            foreach (var value in collection)
            {
                if (result.CompareTo(value) < 0)
                    result = value;
            }
            return result;
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            List<string> strList = new List<string>();
            strList.Add("str1");
            strList.Add("str2");
            strList.Add("str3");
            strList.Add("str4");
            strList.Add("str5");
            strList.Add("str6");

            Console.WriteLine(strList.SumElements());
        }
    }
}
